package com.wanghua.mall.coupon.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wanghua.mall.coupon.entity.SeckillSkuRelationEntity;
import com.wanghua.mall.coupon.service.SeckillSkuRelationService;
import org.springframework.web.bind.annotation.*;

import com.wanghua.mall.coupon.entity.SeckillSessionEntity;
import com.wanghua.mall.coupon.service.SeckillSessionService;
import com.wanghua.common.utils.PageUtils;
import com.wanghua.common.utils.R;

import javax.annotation.Resource;


/**
 * 秒杀活动场次
 *
 * @author wanghua
 * @email 2367279431@qq.com
 * @date 2021-09-08 12:50:11
 */
@RestController
@RequestMapping("/coupon/seckillsession")
public class SeckillSessionController {

    @Resource
    private SeckillSessionService seckillSessionService;

    /**
     * 扫描最近三天的活动
     */
    @GetMapping("/getLatestThreeDaySession")
    public R getLatestThreeDaySession() {
        List<SeckillSessionEntity> list = seckillSessionService.getLatestThreeDaySession();
        return R.ok().put("data", list);
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = seckillSessionService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        SeckillSessionEntity secKillSession = seckillSessionService.getById(id);
        return R.ok().put("seckillSession", secKillSession);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SeckillSessionEntity seckillSession) {
        seckillSessionService.save(seckillSession);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody SeckillSessionEntity seckillSession) {
        seckillSessionService.updateById(seckillSession);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        seckillSessionService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
